package com.climber.android.commonres.helper

import android.animation.Keyframe
import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.animation.ValueAnimator
import android.view.View

/**
 * Created by Mikes at 2020-04-14 15:17
 */
fun View.dozyAnimation(repeatCount : Int = ValueAnimator.INFINITE): ObjectAnimator {
    val shakeFactor = 5f
    val pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION,
            Keyframe.ofFloat(0f, 0f),
            Keyframe.ofFloat(.1f, -3f * shakeFactor),
            Keyframe.ofFloat(.2f, -3f * shakeFactor),
            Keyframe.ofFloat(.3f, 3f * shakeFactor),
            Keyframe.ofFloat(.4f, -3f * shakeFactor),
            Keyframe.ofFloat(.5f, 3f * shakeFactor),
            Keyframe.ofFloat(.6f, -3f * shakeFactor),
            Keyframe.ofFloat(.7f, 3f * shakeFactor),
            Keyframe.ofFloat(.8f, -3f * shakeFactor),
            Keyframe.ofFloat(.9f, 3f * shakeFactor),
            Keyframe.ofFloat(1f, 0f)
    )

    val animator = ObjectAnimator
            .ofPropertyValuesHolder(this, pvhRotate)
            .setDuration(2000)
    animator.repeatMode = ValueAnimator.RESTART
    animator.repeatCount = repeatCount

    return animator
}